local skel = fk.CreateSkill {
  name = "emo__taixin",
  tags = {Skill.Limited},
}

Fk:loadTranslationTable{
  ["emo__taixin"] = "天心",
  [":emo__taixin"] = "限定技，当你受到致命伤害时，你可以重铸所有牌，防止此伤害并对一名其他角色造成同属性的等量伤害，然后修改〖音刃〗：此【杀】造成伤害后，令受伤害的角色翻至背面。",

  ["#emo__taixin-invoke"] = "天心：你可以重铸所有牌，防止此伤害并造成等量伤害，然后修改〖音刃〗",
  ["#emo__taixin-choose"] = "天心:对一名其他角色造成 %arg 点伤害!",

  ["$emo__taixin1"] = "",
  ["$emo__taixin2"] = "",
}

skel:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.damage >= (player.hp + player.shield)
    and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#emo__taixin-invoke" })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:recastCard(player:getCardIds("he"), player, skel.name)
    local targets = room:getOtherPlayers(player)
    if not player.dead and #targets > 0 then
      local tos = player.room:askToChoosePlayers(player, {
        targets = targets, min_num = 1, max_num = 1, skill_name = skel.name, cancelable = false,
        prompt = "#emo__taixin-choose:::"..data.damage,
      })
      if #tos > 0 then
        room:damage{
          from = player,
          to = tos[1],
          damage = data.damage,
          damageType = data.damageType,
          skillName = skel.name,
        }
      end
    end
    room:setPlayerMark(player, "emo__yinren_levelup", 1)
    data:preventDamage()
  end,
})

return skel
